package singleton.type5;

/**
 * 懒汉式(线程安全),同步代码块方式
 * 
 * 
 * @author DFD
 * @date 2023年11月9日
 */
public class Singleton {

	public static void main(String[] args) {
		Singleton instance1 = Singleton.getInstance();
		Singleton instance2 = Singleton.getInstance();
		System.out.println(instance1 == instance2);
	}

	private static Singleton instance;

	private Singleton() {

	}

	public static Singleton getInstance() {
		if (null == instance) {
			synchronized (Singleton.class) {
				instance = new Singleton();
			}
		}
		return instance;
	}
}
